improved junction type detection