acceptance test and some refactoring