add comments and apply slightly refactor.