cleaner code, added nice server shutdown