Added comments, reformatted code