Reorganized viewport controller code.