optimized the code some more