cleaned the source a bit and commented (nearly) everything