Added fix for minor bug that causes an IllegalStateException
Reformatting, removed trailing whitespace