Added ctx and implemented allocation and sorting of rec vals.