Optimized the program to run faster