Fixed bug in mean_displacement calculation