Modified * added more threadsafe code and exceptionhandling along with purging and logging.*