Vectorized the program, and greatly increased speed