Implement pull to refresh and refactor code