Added BaseAccessor and BaseRepository.

Moved a lot of code from the repository layer to these new base classes.