a little work on the algorithm :)