Add tests, fix substitutions and add makepossiblesubstitutions method