some reduction and refactoring