Removed unecessary error flag in a function
Changed the order of error and result in the callback