added test for complex directive ordering, found corresponding logic error, and corrected