fix bug with wrong condition for creating the nested stages