optimized the promram so that is runs faster