Reformatted and fixed functionality