added dependency tracking and sorting