Reformat code before fixing #303
Prevented ArrayOutOfBoundsException and added logging to help diagnose fail condition

fixes #303