all code moved out of xaml for easier page switching