tiny cleanup and null pointer check