Added more documentation and did some code cleanup.