added comments, improved output