cleaning up code, lots more docs