adds comments and reduces some duplication