Order the code

TODO: optimize the code