added auto_ptr for memory cleanup