Moved inner function outside