Fixed a minor bug and other misc changes; enhance testing scipt