add comments and remove dead code