Reformatted code slightly to make it easier to read