Optimized db access in run rep system. Middle of refactoring.