optimize code

1.optimize reg
2.optimize code structure