refactor code for use Fragment.