Fixed some bugs, code runs now at least.