Fixed most unclosed file and lock bugs. Ported some more unit tests, 25 remain. 1518/1971 unit tests passing