Fixed all the errors, typos and a number of bugs