Fixed some infinate loops.