Reorganized to be easier to read