clean up code and add detailed comments.
clean up code and add detailed comments.

NebulousLabs/Sia,mharkus/Sia,mtlynch/Sia,ericflo/Sia,MrStrong/Sia,MrStrong/Sia,ChrisSchinnerl/Sia,NebulousLabs/Sia,ChrisSchinnerl/Sia,mharkus/Sia,mtlynch/Sia,ericflo/Sia