Added logic for editing existing images and galleries, including creation of new gallery if a non-existent name is entered