further refactoring - using IScript extensively to help porting