Moved some common used functions to BaseRepository