Refactor and code tidy up.