Some cleanup starting off from trying to understand the sharing code. Changes include