Fixed weird looping js bug