refractor code