Added comments and reformatted code layout