Added documentation and groomed code.