more minor fixes
use macro to check the global resource
use RETVAL instead of RETURN

if you really want that free call to free anything..