refactors and tidyups