fixed null pointer checking