Added additional optimizations and did more cleanup.