Simplify function's control flow