added comments
Added debug output
minor changes