Reformatted the code and made it a bit more 3.x compatible.