fixed undefined vars ref problem