Fix wrong argument order for calculating distance