Fix invalid cast.
Fix tests.