now finishes execution without crashing
bugfix: added protection against getRegion returning 0