Updates for new DB schema. Fix prioritization queries