changing code according to Dominic's notes