More line logic and smarter handling