Rewrite the submodule logic.

Due to a ridiculous mistake I've made...