Fixes and prevention of null exceptions