Max Attempts

This is just a re-submit of #28 so that the diff is more clear.