Merged Igor and I's code, version 2 has been created