fixing typos and missing var declaration