refactor a bit, add some comments