Switched filestream handling to try-with-resources so they'll actually get closed if something goes wrong