Fixed install script

Discovered a number of bugs in the install script, which are now fixed.