Optimize and simplify the code (1/5 faster)