Started to write the lock logic. It's a mess at the moment...