Fixing type cast bug