1.006 update

Moved code around and rewrote small parts to make the codebase smaller.