Some refactoring and new test features