return 0 if no error when finished