reorganized code
fixed several errors
cleaned up some of the variable names [WIP]