initial file handling stuff done thanks to Brian Johnson