Tidied up a bit. No logic changes.