XD-1044 - Refactor module dependency tracking

See the comments in fe0a1da for more information.