Additional checking for conditions in loops to prevent crash.