Refactoring of ping script. More reliable now.