The 6 lines above are always executed, can't they be moved after this if-else chain in only one place?