Fixed gallery image storing logic