Split out in preparation for WPF version