Improved createFramebuffer function