Added helper for pair casting safely