changed the code structure accroding to feedback