refactored code -- completed the same task in a cleaner manner with less code