Use LineUtil.simplify, rearange some code