Initial attempts at file locking.
Fix locking issues.