move metadata management in command function