fix infinite loop for functions