refactoring away nested ifs