stage2 update

Code rewrite