fixed linedistance function to do what it was supposed to do