extract method to reduce duplication of code