Some refactoring and comments.