Refactored like crazy and cleaned up some code