Fix null case, minor code layout