-removed a lot of redundant code from the model optimization routines, made it much more generic