Improve centering function and add documentation.