Added comments to each function and major loop