bug fix for looping