Standardize callback and cleanup code.

Also the user would need to register an error listener to prevent the code from throwing an error, instead of just checking for the error in the callback.