fixes #1: improve error handling; will clean the locks owned by the current process if exits unexpectedly.