extract common functionality