added a few comments, reformated code