When replacing a string, first thread it through the tailpiece or into the fine tuner. Make sure the ball of the string is pulled all the way up against the slot in the tailpiece or against the prongs on the fine tuner.
Push the upper end of the string through the peg hole so that about half an inch protrudes from the other side. Pulling the slack out of the string, wind the string once around the peg (toward the thin end of the peg) by twisting the peg one turn. Then cross the string over the wound string once and continue winding the remainder of the string toward the thick end of the peg. If the peg hole is near the wall of the peg box, wind up more of the string on the thin end of the peg before crossing over. To keep the strings straight, the last winding should be near, but not touching, the peg box wall. Some musicians intentionally set the strings against the side of the pegbox if a peg is not holding properly, but this can crack the pegbox and should be avoided.
Every time you replace a string, lubricate the notches in the top nut and in the bridge with the tip of a soft pencil. The graphite from the pencil will lubricate the notch, helping the string slide more easily and extending the life of the string. This procedure will also help the bridge remain in the proper position when tuning. The strings will glide over the bridge instead of pulling the bridge toward the fingerboard.