fixed the logic for when it should stop expanding