working code
added comments, changed variables