michael: some refactoring and clean-up