Some refactoring and output tidying...