New formulation and implementation of vibrational self-consistent field theory