MODIFIED: fixed some internal veriable namespacing