Optimized the code a little