additional refactoring and tidying; more redundancies removed