Updated to use proper API for casting.