improve controller and viewport code