Add comments and clean some code