finished to reorganise the code