Cleaned up code. Documented stuff.