made the code cleaner and more functional