Test changes and a bit of refactoring