Replace printf()  with print_handler. Other minor changes.