calculating common points for lines and refactoring