Refactoring and new functional tests