implement print_buffer()
reorganize source code