Fairly significant optimizations using numpy
add missing import