fixing typos and formatting according to Dominic's notes
refactoring context stuff into separate object
changing code according to Dominic's notes