GPS algorithm