Optimized code with fug fixes