Substitution tests corrected

And minor alterations on the engine, due to errors found during the
tests