Updated with latest db queries