Minor refactoring. Add some comments.