Refactored cast helper
Replaced NULL usages to 0, because 0 is already used for pointer initialization in common code.