Added tests for ping and refactor it