Restructure and add configuration
Add file handling
Change to write to filestream