includes algorithm and tests