As dummy atoms are fictitious, the energy of the molecule does not depend on their position, and, therefore, the gradient of the potential energy with respect to the position of dummy atoms is always zero. Because of this, it is possible for the position of the dummy atoms to drift during the course of optimization, reducing the effectiveness of the improper dihedral for which it was added. Our algorithm counteracts this problem by automatically applying three constraints to the position of the dummy atom to ensure it remains in a position that is useful for the optimization. The addition of these constraints also serves to avoid an increase in the dimensionality of the optimization problem upon addition of dummy atoms, though at the cost of turning an otherwise unconstrained optimization into a constrained optimization problem.