a bunch of code to fix some stuff.