Moved a lot of the code around. Readable API for the win