modify the 'cast' function.