changed exception handling to return error message instead of nil