Implemented cast function