A little refactoring to remove duplication and code tidying