Optimized code

Optimize code and use less variables.