Vectorise the loops

This boasts an O(10^4) speed up