complete but buggy logreg