flgLocked added for multi-thread support