implementing some algorithms