refactored pull to refresh code