notes and code modified