fixing var not defined error