Surfactants are molecules that are attracted to water on one end and water-repelling substances on the other. They have a hydrophobic tail that bonds to oil and dirt, and a hydrophilic head that bonds to water molecules. Builders like phosphates are used to raise the pH of the solution and help surfactants get through fats and grease. Hard water contains more minerals like magnesium and calcium that prevent soap from lathering effectively, while soft water contains only sodium and allows for better cleaning. Enzymes and sequestering agents also play roles in the chemistry of laundry detergent.