Fix loading with .ipkg files

This fixes a bug in interactive editing that showed up with hierarchical modules and packages.

It also factors out some common code to a separate function.