working version
working version from jash
slight change
final version