Make vectorization work
Cleaned up loop