Refactored processing of database results