tidy code and add ping option