add delete to free mem from new. Also move declaration so that we don't have to call delete in two places.