Refactoring

consolidated code for new repository concept. renamed classes with more
meaningful names. Removed some duplicated code.