Fix lockfile reduction algorithm (and other things)

:construction: