Added documentation. Refactored.