minor typos fixed
tidy up code