Reformatted code, hopefully made it more readable