Tests and code tidy up