Docs & Cleanup

Documentation added, with examples and everything

Cleanup of internal code and moving functions around for a better
organization.