Refactored repository code