corrected database load and write functions