refactored code up to todo8