cleaned up the code and fixed the ping management bug