Optimization and cleanup

I removed some old code that you weren't using any more, as well as cleaning up code that you do use.