fixed bug: endless loop