Fixed null pointer exceptions