edited code added comments

see summary