Add some comments, refactor some small parts