Removed unnecessary (and confusing) optimizations and tweaked others.