working two algorithms