Added documentation
Cleaned up some code