modify to fix a cast bug