TS-2501 Refactor and improve performance for the case without expansions