refactor and add tests. delete matches selectively on Clearlay