Replace assertions with real error checks