added some optimizations using numpy