implement file locking

This fixes #7