Small refactorings and tidying up