a lot of comments and cleanup