Minor refactoring, adding comments.