Use switch instead of an ugly if/else block