Added retry loop to good ending.
Also included Javadocs.