Sort some dependencies and put them in the right place