polished, added comments