Issue4

Updated API to return errors rather than the function logging and exiting.