implement the resource management code correctly, using approved interfaces. While I'm here, clean up a few things.
Should we ever find ourselves on an RS/6000 this code should work with few changes.