massive speed improvements through vectorization of timespace function