add some comments and refactor the scope of the beans.