fixed an indexing error and the function actually works for objfunc.py