fixed undefined variable issues