Fixed logical loops in viewcontroller

need more test on it