bunch of cleanup optimizations