rewritten after review
copyright added