restruct all the code