Framebuffer code, misc refactoring and cleanup.