Added error handling for every function, which return 1 if succeeds, else the log/output