refactor centering code