Optimize code and use less variables