typos and global declarations removed