moving code from viewDidAppear to viewDidLoad