Could you maybe share this code with the same block above?  Maybe add a method to get the oriented viewport?