Improved safe_import: now handles multiple circular imports in a single file