Refactor the sharing code a bit to make future enhancement more straightforward and to make it not fail on Linux