Improved documentation and did some light refactoring.