fix 'undefined method [] for nil' error