Common parts out of if-else block