Refactored to define fragments with more simple code.