fragments working. code refactored partially