Don't try to ref/unref unused wapi handles
Exporting handle cleanup method so it can be called when an exception occurs