Refactored my script big time