add new tests; some refactoring