Cleaned up code, removed a couple debug functions that were no longer being used