Code refactor.
Added documentation