Null Pointer Exception

Hi,

I was getting a null pointer error on a couple of cleanup functions, this patch checks for existence before testing for property.

Thanks for the library,
nathan