Fixed a compile error and a casting issue of variable.