Moved cast functions to util.py