Some refactoring and arrangements