I discovered a small part of the old positions code was actually better than the new version, so I reused it.  Also removed an extra loop as I realised that two arrays were the same in terms of access.