refactorings, fixes etc