Adds loop guards for retrying. Fixes #62. Style fixes.