extract common part to 2 functions