Refactor
Add error handler