There are some duplicated code for managing apps and domains. Can you do some refactoring to remove it?