Change order to prevent possible thread locking problem and add timeout to help troubleshoot. Ref. dlech/KeeAgent issue #40