Use sorting so un-needed resource applies don't occur. Fixes #43