added safety to refresh.pl; refactor and testing
added safety to refresh.pl; refactor and testing