Replace assert statements with TypeError/ValueError