Tentative fix for invalid cast error