refactoring lua state creation locking