Added file lock management, fixed some synchronization