moved visibleviewport computation to a separate method