refactoring fixes etc