Reorganization of some code in fragment