some partial refactoring