Working code
extended for shutdown, server client