Added Showing Ad Algorithm.

Added Showing Ad Algorithm. And Refactor.