Made the line algorithm tidier