updated with jun's changes
For Testing
Added debugging
identified bug at free() call