Sort operations topologically to prevent undefined operation errors for dependencies

Define dependencies before things that depend on them.

Fixes #2.