small refactor for duplicated code