NEW FEATURE: better debugging and optimization code for db-queries.