Fix lockfile reduction algorithm (and other things)

:game_die: