Replaced all thrown NPEs with IllegalArgumentExceptions.