fix undefined variable bug