Saving all the missing import stuff, plus cleaning up the code a bit.