optimizations and refinements