Add custom error codes and improve returning error codes