Refractor code