Added some code for flatfile issue #48. Need to test.