added shutdown hook and multithreaded modes support