prevent NPE if type is null. Remove unused Environment