added comments and changed formatting