Reduce duplicate code