Had logical errors

Might have got stuck in a infinite loop. Trying to debug