refactored my code a little bit