Added code for computing beta matrices