more improvements

added comments, adjusted formatting, fixed a couple bugs