minor refactoring in DB filling logic