rewrote code using another algorithm