added sharing and refactored