Replace assertion statements with IllegalStateException