add better viewport checking and fix redundant data model