fix bug regarding the dispatching of infill opt funs and clean up code