made various corrections to code, formatting etc