refactor code and comments