completed final_test algorithm, needs editing