moved redundant code out of every if/else-branch