Fixed bug introduced in PR#803 caused by casting

Also changed casts to C++ style casts to removed some of the ambiguity.
Merge pull request #946 from ChuckRozhon/fix_cast_bug

Fixed bug introduced in PR#803 caused by casting