Fix invalid cast