Refactor error handling
Refactor tutorial 2