Refactor and merge tests