Loads of updates

Cleaned up code (a bit).
Added new functions (not all of which work).
And more.