Added detect_crossing code.