added graceful shutdown handling
multithreading to be able to send and receive