Added file writing and improved current file functions (UNTESTED).