Fix problem with generated disposes

Following on from previous pr.