Some refactoring changes with tests