Factor out some lock stuff and turn it into a bean