refactor code and added comments