Refactor database-access, handle null-dates