more relevant test suite
fixed algorithm and added comments