added code to delete dynamically allocated objects