fixed nil class error buy by adding if statement