some refactoring to be able to share common code between separate commands