applied comment and refactor code