Minor refactoring / fixes