Code cleanup + removed some nullpointers