added comments, cleaned things up a bit