Some refactoring, more needed