Fixed too early clean up of the mapped query.