Fixed invalid cast compiler error