complicated optimizations