Reformatting some code; adding David's revision