1. add some comments;
2. some refactor to improve readability and performance