more comments and simpler logic