New tests
Some small code refactor