generous use of auto_ptr to provide better exception safety and make the code