Removed unused functions, added error checking for all calls to custom functions. Error codes need to be updated to reflect potential unique problems with payload script.