Currently we repeat virtually the same code multiple times, which can be avoided by the introduction of a simple helper function.