refactor script using "throws new Error(message);" instead of "var
message,success"