Added additional None check. Hm. This needs refacotring.