replaced throw statements with error callbacks