Fixed up a bunch of code