refractor code with comments