Minor tidy up.
Reinstated clean-up functions