Extra tests + refactoring