add error codes and tests