minor addition of comments and organizing code