added comments to algorithm, added tests for algorithm