Final version for lines.js with cleaner code.