changed test case
improved algorithm