Rewriting and commenting some code