made a few minor changes.

added comments, made some parts more readable, removed useless sections
of code etc...