Replace assertions with ValueError exceptions