Some refactoring, a lot of comments