cleanup + small fix to file locking