New test and some refactoring