script now properly writes to DB