made script more modular and it now accepts target directory
Merge branch 'v1' into v2