re-factor code