Fix race condition when deleting forms/modules

fixes http://manage.dimagi.com/default.asp?94332#584546