Fix tests and global leak