Support for File IO and some code cleanup