Fix various bugs with build script
Fix various bugs with build script

These changes have been tested.

Note:
cp -r foldername/ newfolder # correct
cp -r foldername newfolder # incorrect

Robinlovelace/pct,npct/pct