re-arrange the code