replace some magic numbers
Add robust transition code