Hopefully fix some concurrent modification errors

Done as a 'quick fix' on an iPad, untested and messy. Will tidy up code later.