Fix dependency loading

Loading an IM with dependencies resulted in infinite recursion.
This patch fixes it by loading the dependency only if it's
not loaded already.