Fixed some errors and added a better time updating function which uses the database