Added ping function and cleanup function