Get rid of dead code, add some comments where it's needed.