Reorganized code into more logical order and updated the readme.