Refactor method to simplify logic