fixed bug with infinity loop