Store the time in the database, various fixes