Major code cleanup

Cleaned up code, removed superfluous files and classes, commented bunch
and fixed a few bugs.
Minor fixes and documentation