added comments, initial completed version