Optimized code and gave better names to variables