Wrote minor comments and removed an unnecessary global variable.