incorporate fix from sjackman to prevent segfaults
add support for multiple regions from pull request #5