refactoring boolean switching code