fix invalid cast error