Reformatted code to match current style. I really need to write a script to do this...