fixed auto-purge at middnight, logging and statistics, cleaned up some code.