Cleaned up code

added some comments and cleaned up loose variables.