fix bugs on terminating, remove logging