need to fix infinite loop