Error handling updated to more js like.