fix possible IndexError