restructure the code

restructure the code