A lot of refactoring, comments