works for straight line case