fixed lineId bug --KW
streamlined code a bit --KW