fix for possible nil index bug