Fixes to avoid null pointer exceptions