Fixed null pointer problems