fix for - undefined method [] for nil:NilClass