Add invalid-direction checking; add test output file