added shutdown method which stops server threads and exits event loop