improving generic repository code