Need to figure out infinite loop problem