Move the if null checks to a more sane place