fixed potential problem relating to use of free functions.