added support for many nested levels for fallback logic