Fix bugs and generalize image data layer