working on loop bug