added comments
fixed var names and cleaned up the code