Fixed null pointer errors