Sort dependencies