reduced code duplication a bit