Refactured transition code.