Fixed scope issues and minor typos. Added comments and cleaned up formatting
Added more descriptive comments