Completed the centering function