refactor slightly