code cleanup and fixed typos