Removed a lot of unused code. Simplified some of the code.