added comments, style improvements