handcoded optimizations