Refactored some code, added docs, moved things around, cleaned up