Fixed a bug that was preventing multiple tries in the same scope and added a test for it; moved all recursive calls to function tails; added some comments; removed unnecessary temporary variables