Re-submitting previous code

Wasn't expecting Mehdi's commit to be in this pull request. Probably means there is something more I need to do to fix my fork? Hopefully not.
This pull request contains two commits
1) Two bug fixes.
2) Some tests with BDDfy/AutoSubstitute