Check error return
Refactor