fixes possible NPEs and IllegalArgumentExceptions