adjust line algorithm, and fix plotting