code cleanup (errors for improperly called APIs are now thrown not in the callback)