Fix end() handling in flatMap and merge