Abstract navigation code so it is somewhat reusable