reduce duplicate code