Moved common repostitory functionality into a template class.