improved whitelisting db query