refactor of an if-else that returns