add a bunch of null checks