implementing sharing, cleaning up code