Commenting and formatting

Adding proper comments to every variable and function (other than simple
Get/Set functions).
Fixed formatting on some functions.