Some refactoring / cleanup