optimizations and clean ups