Logic error fix, revised output
Added test script, currently failing