Reorganized code to be easier to browse