Fixed type cast bug