refactor: split outer & inner functions