ps 2-6: added refactored mat's into cxt struct for kf, comments for kf, use ref's for mat lib fn's