Reordering code and fix some name inconsistences.