Fix import error and improve message/exit handling