Code Cleanup and Bug Fixes

Cleaned up and removed a lot of old, buggy code.
Renamed functions to make more sense.
A bunch of small bug fixes