Added documentation; minor refactoring.