Fix some formatting issues, add comments, remove useless code