Large Rewrites

Fixing buggy code and making things make more sense.