restructure the code

restructure the code  and add function need to implement