Refactor the code for the identity match in order to reuse part of it.