Method of preparing sulfur-containing compounds