Slight refactoring. Added a few comments.