Added output parsing and the heart of the optimizing Lddynamic function