Added infinite loop protection and bad ball dimension protection