Added documentation and refactored a little.
Added documentation.