Merged buffer and viewport

Also changed sorting related stuff.