Replace two asserts by checks and error messages.