Tidy up the view chaning code