continued on opt implementation, found some bugs