fixed a few bugs, some typos in terms of indexing and the exploding of beta