fixed algorithm and added extra tests