adding fix to an if statement to stop seeing errors in console