refactor the viewport.js.