refactored db query creation and result mapping