fixed undefined variable bug