Refactor the fragment related code