fig fixed,restruct the code