fixes undefined variable bug