fix bug discovered with unit tests in converting generic scripts
add unit tests in core