added more documentation and tweeked a few algorithms