Some refactoring fixes