Cleaned up code, ran static analysis, removed a ton of warnings