modularized database access function