some work on viewports.js

Refactor viewport creation
Add before and after methods to manage ordering