remove print and do memory cleanup in debug mode