cleaned up by addeding a helper function: cast.