Finish most of the function.

Finish most of function and ready for function fg.