fix incorrect assumption, minor refactoring