Refactoring, fixes, cleanup and duplicate line feature.