Fix heap corruption