Documentation and refactoring

Cleaning up code, adding documentation and removing duplicate method