Backport improvements from the Scala port to the F# implementation, also updated C5 dependency in the process.