Still buggy, but viewport arithmetic refactored a bit