Replaced repeated code with helper method