Optimized code slightly