Some major refactoring to support Foreman