updated the code to reflect feedback