reorganize the code