Working file-writing version. Add database stuff next
Added database output