Weird infinite loop problem in solve