add preview code. and refactor structure.