Optimized code with comments.