tutorial fixes and refactoring