Code Cleanup

Cleaned up some code and simple performance improvements