Handle error case
Move callback out of for