problem 12: combining all optimizations together