fixed several infinite loop errors