Fix cast exception and revert regression.