Algorithm Update

1. Fixes after testing with PHPUnit.