fixed undefined method for nil class error