Refactor code in the HomesController