Implement transition detection and add test cases