some optisations that generally improve speed - reduce calls to np.dot