Fix viewport arranging logic