Added derivedFrom query, and improved performance significantly (though derivedFrom is slow)