File writer and small refactor.