better gravity algorithm