implemented the auto-running function.