null check fix and some clean up