reformatting and adding comments

re-formatting code and adding comments