Fixed bug in dependencies sorting of plugins.

The topological sort of plugin dependencies had a slight bug which was
causing some unexpected behaviour.