re-factor code layout