reorganise and rewrite