Algorthim fully written, but buggy

Issue with direction of conditional branching.