added comments and reformatted