loads of comments, and some refactor