Add better error-handling to gallery.