used auto_ptr to avoid memory leaks