Updated function to compute possible substitutions

Even though the new function is quite mre efficient than the older one,
it still has a lot of limmitations, so we may not use it at all
an compute only substitutions of one level