Added automated testing.
Variable ans is now set to previous valid answer.