fixed the bug in select region

the bug was introduced in the last set of changes, one for...end loop closed too early. fixed in the repository, sorry for the quick and dirty fix bypassing the pull request.