Refactored my code to be simpler