address race condition in cleanup methods

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>