resize viewer, and refactor the codes