better flow in dispatchMetadata function