Achieved some speedup with the use of NumPy