added some comments and fixed typos