refactoring with minor semantic changes