Replace asserts with checks which gives meaningful error messages