Fixing error 'undefined method each for Nil class'