refactor, extract common functionality in helper