Refactor and tidy up.