Fixed a couple bugs that caused infinite loops