fix object freeing bug