optimized the code make it run faster