restructure the code